package com.minyon_web_admin.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.minyon_web_admin.common.utils.StringUtil;
import com.minyon_web_admin.common.bean.ResCode;
import com.minyon_web_admin.common.utils.ResponseUtil;
import com.minyon_web_admin.common.mybatis.MybatisDao;
import com.minyon_web_admin.common.page.PageUtil;
import com.minyon_web_admin.common.base.BaseService;
import com.minyon_web_admin.server.ISysMenu;
import com.minyon_web_admin.model.SysMenuBean;

/**
 * 
 * <br>
 * <b>功能：</b>SysMenuService<br>
 */
@Service
public class SysMenuService extends BaseService implements ISysMenu {

	protected final Logger minYonlogger = (Logger) LoggerFactory.getLogger(getClass());
	@Autowired
	MybatisDao mybatisDao;

	@Override
	public Map<String, Object> getListPage(Map<String, Object> reqMap) {
		minYonlogger.info("查询分页列表");
		PageUtil<SysMenuBean> page = new PageUtil<SysMenuBean>(reqMap);
		reqMap.put("page", page);
		Map<String, Object> resMap = new HashMap<String, Object>();
		List<SysMenuBean> list = mybatisDao.getList("SysMenuMapper.listPageSysMenu", reqMap);
		if (list.size() > 0) {
			page.setResult(list);
			resMap.put("RESULT", page);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}

	@Override
	public Map<String, Object> queryListInfo(Map<String, Object> reqMap) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		List<SysMenuBean> list = mybatisDao.getList("SysMenuMapper.queryListInfo", reqMap);
		if (list.size() > 0) {
			resMap.put("RESULT", list);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}

	@Override
	public Map<String, Object> queryDetail(Map<String, Object> reqMap) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		SysMenuBean bean = mybatisDao.get("SysMenuMapper.queryDetail", reqMap);
		if (StringUtil.isNotEmpty(bean)) {
			resMap.put("RESULT", bean);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}

	@Override
	public Map<String, Object> deleteInfo(String id) {
		minYonlogger.info("删除数据");
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.delete("SysMenuMapper.deleteInfo", id);
		if (flag > 0) {
			resMap.put("RESULT", flag);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_DELETE_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "删除失败", resMap, false);
		}
	}

	@Override
	public Map<String, Object> insertInfo(SysMenuBean bean) {
		minYonlogger.info("新增数据");
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.insert("SysMenuMapper.insertInfo", bean);
		if (flag > 0) {
			resMap.put("RESULT", flag);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_INSERT_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "添加失败", resMap, false);
		}
	}

	@Override
	public Map<String, Object> updateInfo(SysMenuBean bean) {
		minYonlogger.info("更新数据");
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.update("SysMenuMapper.updateSelective", bean);
		if (flag > 0) {
			resMap.put("RESULT", flag);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_UPDATE_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "更新失败", resMap, false);
		}
	}

	@Override
	public Map<String, Object> queryPermissionByUserId(String userId) {
		minYonlogger.info("查询用户的权限");
		Map<String, Object> resMap = new HashMap<String, Object>();
		List<SysMenuBean> lt = mybatisDao.getList("SysMenuMapper.queryPermissionByUserId", userId);
		if (lt.size() > 0) {
			resMap.put("RESULT", lt);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "", ResCode.SUCCESS_UPDATE_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD, ResCode.EXPECT_NOT_MATCH, "查询失败", resMap, false);
		}
	}
}
